<!--
Copyright (C) 2013 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!DOCTYPE html>
<html>
  <script src="https://www.gstatic.com/cast/js/receiver/1.0/cast_receiver.js">
  </script>
  <script type="text/javascript">

    cast.receiver.logger.setLevelValue(0);
    
    // Initialize and start the media playing receiver
    var receiver = new cast.receiver.Receiver(
        '457fadb0-469c-4adf-ad80-f5b6cf7440ec', 
        [cast.receiver.RemoteMedia.NAMESPACE],
        "",
        5);
    var remoteMedia = new cast.receiver.RemoteMedia();
    remoteMedia.addChannelFactory(
        receiver.createChannelFactory(cast.receiver.RemoteMedia.NAMESPACE));

    receiver.start();

    window.addEventListener('load', function() {
      var elem = document.getElementById('vid');
      remoteMedia.setMediaElement(elem);

      var checkStatus = function() {
        var status = document.getElementById('status');
        var st = remoteMedia.getStatus()['state'];
        
        if( st == 0 || remoteMedia.getStatus()['current_time'] == 0 ) {
            status.style.display = 'block';
        }
        else {
            if( st == 1 && remoteMedia.getStatus()['current_time'] > 0 ) {
                status.innerHTML = 'Paused...';
                status.style.display = 'block';
            }
            else {
                status.innerHTML = remoteMedia.getStatus()['current_time'];
                status.style.display = 'none';
                elem.style.display = 'block';
            }
        }
      }
      setInterval(checkStatus, 1000);
    });
  </script>
  <title>Media Player App</title>
  <body>
    <video id="vid"
           style="position:absolute;top:0;left:0;height:100%;width:100%">
    <div id="status" style="display:none; font-size:300%; position:absolute;top:40%;left:40%;">
      <img src="/images/chrome_loading.gif" width="60%">
    </div>
  </body>
</html>
